using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class JobSeekers_applyjob : System.Web.UI.Page
{
    string connectionString;
    string jsemail;
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
        WebConfigurationManager.ConnectionStrings[
          "RecruitVietnam"].ConnectionString;
        jsemail = Convert.ToString(Session["jsemail"]);
        if (jsemail == "")
            Response.Redirect("login.aspx");
        if(!IsPostBack)
        {
            Page page = PreviousPage;
            if (page == null)
            {
                Response.Redirect("search.aspx");
            }
            else
            {
                txtJobID.Text = ((TextBox)
                page.FindControl("txtJobID")).Text;
                txtASPXPage.Text = ((TextBox)
                page.FindControl("txtASPXPage")).Text;
                txtCompany.Text = ((TextBox)
                page.FindControl("txtCompany")).Text;
                literalJobTitle.Text = ((TextBox)
                page.FindControl("txtJobTitle")).Text;
                ShowLettersAndResumes();
            }
        }
    }

    void ShowLettersAndResumes()
    {
        Common cls = new Common(connectionString);
        DataSet dataSet = 
        cls.GetDataSet("SPResumeAndLetter", 
        "@UserID", Convert.ToString(
        Session.Contents["jsuserid"]));
        RadioButtonListHelper helpper = 
        new RadioButtonListHelper();
        helpper.FillDataTableToRadioButtonList(
        dataSet.Tables[0], rdoCoverLetter, 
        "None", "0", "Subject", "LetterID", 
        Session["jscoverletter"].ToString());           
        helpper = new RadioButtonListHelper();
        helpper.FillDataTableToRadioButtonList(
        dataSet.Tables[1], rdoResume, "ResumeTitle", 
        "ResumeID", Session["jsresume"].ToString());
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {         
         
        string coverLetterID = 
        rdoCoverLetter.SelectedValue;        
        string resumeID = rdoResume.SelectedValue;
        if (resumeID != "") 
            resumeID = Session["jsresume"].ToString();
        RecruitVietnam cls = 
        new RecruitVietnam();
        cls.ConnectionString = connectionString;
        if (cls.ApplyJob(txtJobID.Text, 
        resumeID, coverLetterID))
        {
            MailProvider mailProvider = new MailProvider();
            mailProvider.SendMail(jsemail,
            "Apply Job", "You have applied job[" 
            + literalJobTitle.Text 
            + "] to company: " 
            + txtCompany.Text);
            literalError.Text = 
            "<br>You have applied job successful.<br>\""
            + txtCompany.Text + 
            "\" will contact you soon.<br><br><br>"+
            "<input id=\"btnBack\" onclick=\""+
            "window.history.go(-1);\" "+
            "type=\"button\" value=\"Back\" />  "+
             "<input id=\"btnSearch\" onclick=\"" +
            "window.open('search.aspx',target='_main');\" " +
            "type=\"button\" value=\"Continue Search\" />";
            tableView.Visible= false;
        }
        else
            literalError.Text = cls.ErrorMessage;
       
    }
}
